<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录界面</title>
</head>
<body>
<script>
    function checkUser(){
        const username = document.getElementById("username").value;
        if(username == ""){
            document.getElementById("tishiUsername").innerHTML ="用户名不能为空";
            return;//必须要写return跳出
        }else{
            document.getElementById("tishiUsername").innerHTML ="";
        }

        const pwd = document.getElementById("pwd").value;
        if(pwd == ""){
            document.getElementById("tishiPwd").innerHTML ="密码不能为空";
            return;
        }else{
            document.getElementById("tishiPwd").innerHTML ="";
            const reg = /^[0-9]{6}$/;
            if(!reg.test(pwd)){
                document.getElementById("tishiPwd").innerHTML ="密码只能为6位数字";
                return;
            }
        }
    }
</script>
<style>
    span{
        color:red;
    }
</style>
</head>
<body>

<form action="javascript01.html" method="get" align="center" onsubmit="return false">
    <p>
        账号：
        <input name="username" id="username">
        <span>*</span>
        <span id="tishiUsername"></span>
    </p>
    <p>
        密码：<input type="password" name="password" id="pwd">
        <span>*</span>
        <span id="tishiPwd"></span>
    </p>
    <p><input type="submit" value="登录" onclick="checkUser()"></p>

</form>


</body>
</html>